package org.example.quartz.BIP;

import cn.hutool.core.date.StopWatch;
import cn.hutool.db.Entity;
import cn.hutool.db.Session;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.quartz.service.LogService;
import org.example.quartz.service.OrgService;
import org.example.quartz.service.UtilService;
import org.example.quartz.task.QuartzTaskJob;
import org.example.quartz.util.DataSourceUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
// 再Job被执行结束后，将会更新JobDataMap，这样下次Job执行后悔使用新的值而不是初始值
@PersistJobDataAfterExecution
// 同一时间将只有一个Job实例被执行，为了避免并发问题导致数据紊乱，建议这两个注解一起使用
@DisallowConcurrentExecution
public class SubjectQuartz_BIP implements QuartzTaskJob {

    Map<String, Object> gsMap = DataSourceUtil.getGS();
    //全局接口配置
    String IP = (String) gsMap.get("IP");
    String PORT = (String) gsMap.get("PORT");
    String ECC = (String) gsMap.get("ECC");
    String Bearer = (String) gsMap.get("Bearer");
    //日志
    LogService loginfo = SpringUtil.getBean(LogService.class);
    //orgService
    OrgService orgService = SpringUtil.getBean(OrgService.class);
    //orgService
    UtilService utilService = SpringUtil.getBean(UtilService.class);


    /**
     * 科目接口
     * 接口地址：GSCloud文档3.9
     * http://ip:port/api/jg/syncbddata/v1.0/bdsyncinterface/syncKmzd
     **/
    @SneakyThrows
    @Override
    public void execute(JobExecutionContext context) {
        try {
            //传入变量 lastTime 最后抓取时间
            //链接BIP数据库，查询出需要同步的数据，根据TS时间进行判断。
            //TS从中间库表获取到最后一次更新时间，根据此时间进行增量查询推送；
            //中间库日志表记录推送日志，成功、失败、返回信息等（备查）
            //中间库记录最后推送数据的时间，根据时间进行下次查询的条件；
            //查询脚本
            //String YEAR = utilService.getYEAR();
            int YEAR = LocalDateTime.now().getYear();
            //获取年度
            List<Integer> years = utilService.getYEARS();
            JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
            //查询数据，根据数据结果推送给GS浪潮
            Session oracleSession = DataSourceUtil.getLSOracleSession();
            //根据组织编码，查询出账套信息，如果有多个账套，轮询进行处理
            List<Map<String, Object>> yyztCodeMap = orgService.selectAllGLCode(jdbcTemplate);
            //账簿轮询
            for (int x = 0; x < yyztCodeMap.size(); x++) {
                String methodName = "SubjectQuartz";
                methodName += (String) yyztCodeMap.get(x).get("gsztCode");
                String ts = utilService.getTs(methodName, jdbcTemplate);
                String yyCode = (String) yyztCodeMap.get(x).get("yyCode");
                String yyztCode = (String) yyztCodeMap.get(x).get("yyztCode");
                //gsCode
                String gsztCode = (String) yyztCodeMap.get(x).get("gsztCode");
                //kmtx
                String kmtx = (String) yyztCodeMap.get(x).get("kmtx");
                //yykmtx
                String yykmtx = (String) yyztCodeMap.get(x).get("yykmtx");
                //取中间库表yy_org_orgs     Gscocde
                String gsCode = (String) yyztCodeMap.get(x).get("gsCode");
                //2、根据时间查询数据集 (停用和删除的过滤掉，暂不考虑，线下处理)
                String selectSQL = "SELECT-- 会计年度（BIP无年度概念，取当前年度）\n" +
                        "TO_CHAR( SYSDATE, 'YYYY' ) AS YEAR,\n" +
                        "-- 科目体系编号\n" +
                        "'kmtx' AS CHARTOFACC,\n" +
                        "BS.CODE AS KMTX,\n" +
                        "B.ACCLEV AS 级次,\n" +
                        "-- 账簿编号\n" +
                        "ORG.CODE AS LEDGER,\n" +
                        "-- 会计类型\n" +
                        "'0' AS ACCOUNTTYPE,\n" +
                        "-- 核算组织编码\n" +
                        "ORG.CODE AS ACCORGCODE,\n" +
                        "-- 父级科目编码\n" +
                        "A1.CODE AS PARENTCODE,\n" +
                        "-- 科目属性编号\n" +
                        "'0' || BT.CCODE AS ACCTITLEPROP,\n" +
                        "-- 科目编号\n" +
                        "B.CODE AS CODE,\n" +
                        "-- 科目名称-- SUBSTR(B.NAME, INSTR(B.NAME, '\\',-1)1) AS NAME,\n" +
                        "A.NAME,\n" +
                        "-- 全称策略\n" +
                        "'0' AS FULLNAMEROLE,\n" +
                        "-- 科目全称\n" +
                        "B.NAME AS FULLNAME,\n" +
                        "-- 助记码\n" +
                        "B.REMCODE AS MNEMONICCODE,\n" +
                        "-- 来源方式\n" +
                        "'4' AS SRCTYPE,\n" +
                        "-- 余额方向 1、借2、贷\n" +
                        "( CASE WHEN B.BALANORIENT = 0 THEN '1' ELSE '2' END ) AS BALANCEDIR,\n" +
                        "-- 现金科目（0、非现金1、现金2、银行存款3、其他现金及现金等价物）\n" +
                        "B.CASHTYPE AS CASHACCTITLE,\n" +
                        "-- 是否日记账（1、是0、否）\n" +
                        "'0' AS ISJOURNALENTRY,\n" +
                        "-- 是否银行账（1、是0、否）\n" +
                        "'0' AS ISBANKBOOK,\n" +
                        "-- 是否允许账簿在下级增加（1、是0、否）\n" +
                        "'1' AS ISALLOWLEDGERCHILDADD,\n" +
                        "-- AUTHLAYER\\权限级数\\\\\\1\n" +
                        "'1' AS AUTHLAYER,\n" +
                        "-- AUTHFLAG\\权限标志\\\\\\0\n" +
                        "'0' AS AUTHFLAG,\n" +
                        "-- REMARK\\备注\\\\\\\\\n" +
                        "'' AS REMARK,\n" +
                        "-- ISDISABLED\\是否启用\\STRING\\1\\是\\1是0否\\\n" +
                        "'1' AS ISDISABLED,\n" +
                        "-- TYPEFLAG\\公有私有标志\\STRING\\1\\是\\一级科目传1（公有科目）其他级次科目传 2（账簿科目）\\\n" +
                        "( CASE WHEN B.ACCLEV = 1 THEN '1' ELSE '2' END ) AS TYPEFLAG,\n" +
                        "-- 是否辅助核算  辅助核算有任意一项为1，则为1\n" +
                        "( CASE WHEN FZ.FZSUM IS NOT NULL THEN '1' ELSE '0' END ) AS ISASSISTACC,\n" +
                        // "'1' AS ISASSISTACC,\n" +
                        "-- ISDEPT\\部门核算\\\\1是 0否\n" +
                        "'0' AS ISDEPT,\n" +
                        "-- ISPERSON\\个人核算\\\\1是 0否\n" +
                        "'0' AS ISPERSON,\n" +
                        "-- ISCANDS\\往来单位核算\\\\1是0否\n" +
                        "'0' AS ISCANDS,\n" +
                        "-- ISCRCY\\外币核算\\\\0:不核算1:单一币种核算2:全币种核算\n" +
                        //  "'' AS ISCRCY,\n" +
                        "'2' AS ISCRCY,\n" +
                        "-- CRCY\\核算外币编号\\\\\n" +
                        "'' AS CRCY,\n" +
                        "-- ISQTY\\数量核算\\\\1是0否\n" +
                        "'0' AS ISQTY,\n" +
                        "-- QTYEX01\\数量辅助项1\\\n" +
                        "'' AS QTYEX01,\n" +
                        "-- QTYEX02\\数量辅助项2\\\\\n" +
                        "'' AS QTYEX02,\n" +
                        "-- QTYEX03\\数量辅助项3\\\n" +
                        "'' AS QTYEX03,\n" +
                        "-- ISIT\\内部交易\\\\1是0否\n" +
                        "( CASE WHEN B.INNERINFO = 'Y' THEN '1' ELSE '0' END ) AS ISIT,\n" +
                        "-- ISITNOTNULL\\制单时必须录入对方单位\\\\1是0否\n" +
                        "'' AS ISITNOTNULL,\n" +
                        "-- CANDSRANGE\\对方单位范围\\0:全部1:内部单位2:外部单位\n" +
                        "'' AS CANDSRANGE,\n" +
                        "-- BIZCTRL\\业务限制\\\\0:手工制单科目1:通用科目2:业务科目\n" +
                        "'' AS BIZCTRL,\n" +
                        "-- ACCBOOKSTYLE\\账页格式\\\\0:不设置1:金额账2:数量金额账3:外币金额账4:数量外币金额账\n" +
                        "'' AS ACCBOOKSTYLE,\n" +
                        "-- ENDPERIODBAL\\期末结平\\\\0:不检查1:月末检查2:季末检查3:年末检查\n" +
                        "'' AS ENDPERIODBAL,\n" +
                        "-- ISTRANSFERBAL\\结转余额\\\\1是0否\n" +
                        "'' AS ISTRANSFERBAL,\n" +
                        "-- ISSAMEASBALDIR\\制单时必须同向发生\\\\1是0否\n" +
                        "'' AS ISSAMEASBALDIR,\n" +
                        "-- ISDEFICITCTRL\\赤字控制\\\\1是0否\n" +
                        "'' AS ISDEFICITCTRL,\n" +
                        "-- ISCANDSBIZNUM\\往来核算必填业务号\\\\1是0否\n" +
                        "'' AS ISCANDSBIZNUM,\n" +
                        "-- ISCC\\成本中心核算\\\\1是0否\n" +
                        "'' AS ISCC,\n" +
                        "-- 自定义EXTENDCHAR\n" +
                        "'' AS EXTENDCHAR,\n" +
                        "-- 自定义ISUSERDEFNITEM\n" +
                        "'' AS ISUSERDEFNITEM,\n" +
                        "-- 自定义ISREFBIZ\n" +
                        "'' AS ISREFBIZ,\n" +
                        "-- 自定义EXTENDNUM\n" +
                        "'' AS EXTENDNUM,\n" +
                        "A.TS AS TS,\n" +
                        "A.PK_ACCASOA AS ID \n" +
                        "FROM \n" +
                        "\t" + utilService.getOracle() + ".BD_ACCASOA" + utilService.getHZ() + "  A\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".BD_ACCOUNT" + utilService.getHZ() + " B ON A.PK_ACCOUNT = B.PK_ACCOUNT\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".BD_ACCOUNT" + utilService.getHZ() + " A1 ON B.PID = A1.PK_ACCOUNT\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".BD_ACCTYPE" + utilService.getHZ() + " BT ON B.PK_ACCTYPE = BT.PK_ACCTYPE\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".BD_ACCCHART" + utilService.getHZ() + " AC ON A.PK_ACCCHART = AC.PK_ACCCHART\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".bd_accsystem" + utilService.getHZ() + " BS ON AC.PK_accsystem = BS.pk_accsystem\n" +
                        "\tLEFT JOIN " + utilService.getOracle() + ".ORG_ORGS" + utilService.getHZ() + " ORG ON AC.PK_ORG = ORG.PK_ORG\n" +
                        "\tLEFT JOIN ( SELECT PK_ACCASOA, COUNT( 1 ) AS FZSUM FROM " + utilService.getOracle() + ".BD_ACCASS" + utilService.getHZ() + " GROUP BY PK_ACCASOA ) FZ ON A.PK_ACCASOA = FZ.PK_ACCASOA \n" +
                        "WHERE\n" +
                        "\tBS.CODE = '" + yykmtx + "' and B.CODE IS NOT NULL\n" +
                        "\tAND\n" +
                        //"\tA.pk_accchart = (SELECT PK_CURRACCCHART FROM "+utilService.getOracle()+".ORG_ACCOUNTINGBOOK"+utilService.getHZ()+" WHERE CODE = '"+yyztCode+"')" +
                        "\tORG.CODE IN ('" + yyCode + "')\n" +
                        "\tAND\n" +
                        "\tA.TS > '" + ts + "' \n" +
                        "ORDER BY\n" +
                        "\tB.ACCLEV ASC,\n" +
                        "\tA.TS ASC,\n" +
                        "\tB.CODE ASC";
                //执行sql
                List<Entity> query = oracleSession.query(selectSQL);
                //查询sql（查询中间表对照关系）
                String tsSql = "SELECT \n" +
                        "id,\n" +
                        "num,\n" +
                        "doccode,\n" +
                        "docname,\n" +
                        "gscode,\n" +
                        "tablename,\n" +
                        "tablekey,\n" +
                        "codekey,\n" +
                        "namekey,\n" +
                        "fzpk,\n" +
                        "freekey,\n" +
                        "istrue,\n" +
                        "ts \n" +
                        "FROM\n" +
                        " " + utilService.getGSYY() + ".freemap f \n";
                List<Map<String, Object>> maps = jdbcTemplate.queryForList(tsSql);
                //拼装数据，推送给浪潮
                if (query.size() > 0) {
                    for (Map<String, Object> gSmap : query) {
                        //获取公司账套编码
                        gsztCode = (String) yyztCodeMap.get(x).get("gsztCode");
                        //查询辅助核算项
                        String FZSQL = "select \n" +
                                "org.code as orgcode,\n" +
                                "d.code,\n" +
                                "d.name,\n" +
                                "c.code as fzcode,\n" +
                                "c.name as fzname\n" +
                                "from \n" +
                                " " + utilService.getOracle() + ".BD_ACCASS" + utilService.getHZ() + " a\n" +
                                "LEFT JOIN \n" +
                                " " + utilService.getOracle() + ".bd_accasoa" + utilService.getHZ() + " b on a.PK_ACCASOA = b.PK_ACCASOA\n" +
                                "left join \n" +
                                " " + utilService.getOracle() + ".bd_account" + utilService.getHZ() + " d on b.pk_account = d.pk_account\n" +
                                "left join \n" +
                                " " + utilService.getOracle() + ".BD_ACCASSITEM" + utilService.getHZ() + " c on a.pk_entity = c.pk_accassitem\n" +
                                "left join \n" +
                                " " + utilService.getOracle() + ".bd_accchart" + utilService.getHZ() + " ac on a.PK_ACCCHART = ac.PK_ACCCHART\n" +
                                "left join \n" +
                                " " + utilService.getOracle() + ".bd_accsystem" + utilService.getHZ() + " ba on ac.pk_accsystem = ba.pk_accsystem\n" +
                                "left join \n" +
                                " " + utilService.getOracle() + ".org_orgs" + utilService.getHZ() + " org on ac.pk_org = org.pk_org\n" +
                                "where \n" +
                                "d.code = '" + gSmap.get("CODE") + "'\n" +
                                "and\n" +
                                "ba.code = '" + yykmtx + "'\n" +
                                "and\n" +
                                "org.code = '" + gSmap.get("ACCORGCODE") + "'";
                        List<Entity> fzQuery = oracleSession.query(FZSQL);
                        //辅助核算处理
                        if (fzQuery.size() > 0) {
                            for (Map<String, Object> fzmap : fzQuery) {
                                System.out.println(fzmap.get("fzcode") + "：科目辅助核算处理");
                                String fzCode = (String) fzmap.get("fzcode");
                                //判断是否是部门、人员、往来单位，给是否赋值
                                for (Map<String, Object> map : maps) {
                                    if (fzCode.equals(map.get("doccode"))) {
                                        //根据查询的数据进行判断
                                        //是否部门、个人、往来
                                        String istrue = (String) map.get("istrue");
                                        if (istrue.equals("DEPT")) {
                                            gSmap.put("ISDEPT", "1");
                                        } else if (istrue.equals("PERSON")) {
                                            gSmap.put("ISPERSON", "1");
                                        } else if (istrue.equals("CANDS")) {
                                            gSmap.put("ISCANDS", "1");
                                        }
                                    }
                                }
                            }
                        } else {
                            System.out.println(gSmap.get("CODE") + "该科目无辅助核算");
                        }
                        //如果是1级科目，则LEDGER、ACCORGCODE 需要置空 TYPEFLAG 为 1  传空
                        if (gSmap.get("TYPEFLAG").equals("1")) {
                            gsztCode = "";
                            gsCode = "";
                        }
                        //获取年度
                        //     for (Integer YEAR : years) {
                        //报文拼接
                        String GsJson = "{\n" +
                                "\"YEAR\":\"" + YEAR + "\",\n" +
                                "\"CHARTOFACC\":\"" + kmtx + "\",\n" +
                                "\"LEDGER\":\"" + gsztCode + "\",\n" +
                                "\"ACCOUNTTYPE\":\"" + gSmap.get("ACCOUNTTYPE") + "\",\n" +
                                "\"ACCORGCODE\":\"" + gsCode + "\",\n" +
                                "\"PARENTCODE\":\"" + gSmap.get("PARENTCODE") + "\",\n" +
                                "\"ACCTITLEPROP\":\"" + gSmap.get("ACCTITLEPROP") + "\",\n" +
                                "\"CODE\":\"" + gSmap.get("CODE") + "\",\n" +
                                //"\"NAME\":\"" + gSmap.get("NAME") + "\",\n" +
                                "\"NAME\":\"" + gSmap.get("CODE")+gSmap.get("NAME") + "\",\n" +
                                // "\"FULLNAMEROLE\":\"" + gSmap.get("FULLNAMEROLE") + "\",\n" +
                                // "\"FULLNAME\":\"\",\n" +
                                "\"MNEMONICCODE\":\"" + gSmap.get("MNEMONICCODE") + "\",\n" +
                                "\"SRCTYPE\":\"" + gSmap.get("SRCTYPE") + "\",\n" +
                                "\"BALANCEDIR\":\"" + gSmap.get("BALANCEDIR") + "\",\n" +
                                "\"CASHACCTITLE\":\"" + gSmap.get("CASHACCTITLE") + "\",\n" +
                                "\"ISJOURNALENTRY\":\"" + gSmap.get("ISJOURNALENTRY") + "\",\n" +
                                "\"ISBANKBOOK\":\"" + gSmap.get("ISBANKBOOK") + "\",\n" +
                                "\"ISALLOWLEDGERCHILDADD\":\"" + gSmap.get("ISALLOWLEDGERCHILDADD") + "\",\n" +
                                "\"AUTHLAYER\":\"" + gSmap.get("AUTHLAYER") + "\",\n" +
                                "\"AUTHFLAG\":\"" + gSmap.get("AUTHFLAG") + "\",\n" +
                                "\"REMARK\":\"" + gSmap.get("REMARK") + "\",\n" +
                                "\"ISDISABLED\":\"" + gSmap.get("ISDISABLED") + "\",\n" +
                                "\"TYPEFLAG\":\"" + gSmap.get("TYPEFLAG") + "\",\n" +
                                "\"ISASSISTACC\":\"" + gSmap.get("ISASSISTACC") + "\",\n" +
                                "\"ISDEPT\":\"" + gSmap.get("ISDEPT") + "\",\n" +
                                "\"ISPERSON\":\"" + gSmap.get("ISPERSON") + "\",\n" +
                                "\"ISCANDS\":\"" + gSmap.get("ISCANDS") + "\",\n" +
                                "\"ISCRCY\":\"" + gSmap.get("ISCRCY") + "\",\n" +
                                "\"CRCY\":\"" + gSmap.get("CRCY") + "\",\n" +
                                "\"ISQTY\":\"" + gSmap.get("ISQTY") + "\",\n" +
                                "\"QTYEX01\":\"" + gSmap.get("QTYEX01") + "\",\n" +
                                "\"QTYEX02\":\"" + gSmap.get("QTYEX02") + "\",\n" +
                                "\"QTYEX03\":\"" + gSmap.get("QTYEX03") + "\",\n" +
                                "\"ISIT\":\"" + gSmap.get("ISIT") + "\",\n" +
                                "\"ISITNOTNULL\":\"" + gSmap.get("ISITNOTNULL") + "\",\n" +
                                "\"CANDSRANGE\":\"" + gSmap.get("CANDSRANGE") + "\",\n" +
                                "\"BIZCTRL\":\"" + gSmap.get("BIZCTRL") + "\",\n" +
                                "\"ACCBOOKSTYLE\":\"" + gSmap.get("ACCBOOKSTYLE") + "\",\n" +
                                "\"ENDPERIODBAL\":\"" + gSmap.get("ENDPERIODBAL") + "\",\n" +
                                "\"ISTRANSFERBAL\":\"" + gSmap.get("ISTRANSFERBAL") + "\",\n" +
                                "\"ISSAMEASBALDIR\":\"" + gSmap.get("ISSAMEASBALDIR") + "\",\n" +
                                "\"ISDEFICITCTRL\":\"" + gSmap.get("ISDEFICITCTRL") + "\",\n" +
                                "\"ISCANDSBIZNUM\":\"" + gSmap.get("ISCANDSBIZNUM") + "\",\n" +
                                "\"ISCC\":\"" + gSmap.get("ISCC") + "\",\n" +
                                "\"EXTENDCHAR01\":\"" + gSmap.get("CODE") + "\",\n" +
                                "\"EXTENDCHAR02\":\"" + gSmap.get("NAME") + "\",\n";
                        //根据辅助核算判断
                        for (int z = 1; z < 100; z++) {
                            //判断是否有辅助核算
                            String ISUSERDEFNITEMVALUE = "0";
                            if (fzQuery.size() > 0) {
                                for (Map<String, Object> fzmap : fzQuery) {
                                    String fzCode = (String) fzmap.get("fzcode");
                                    //判断是否是部门、人员、往来单位，给是否赋值
                                    for (Map<String, Object> map : maps) {
                                        if (fzCode.equals(map.get("doccode"))) {
                                            String istrue = (String) map.get("istrue");
                                            if (istrue.equals("NO")) {
                                                if (Integer.parseInt((String) map.get("gscode")) == z) {
                                                    ISUSERDEFNITEMVALUE = "1";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (z < 10) {
                                GsJson += "\"ISUSERDEFNITEM0" + z + "\":\"" + ISUSERDEFNITEMVALUE + "\",\n";
                            } else {
                                GsJson += "\"ISUSERDEFNITEM" + z + "\":\"" + ISUSERDEFNITEMVALUE + "\",\n";
                            }
                        }
                        //去掉拼接的最后一个字符
                        GsJson = GsJson.substring(0, GsJson.lastIndexOf(','));
                        GsJson += "}";
                        //调用GS接口，推送给GS浪潮，获取返回值;
                        //1、推送用户档案
                        GsJson = GsJson.replace("null", "").replace("\\", "\\\\");  // 反斜杠;
                        StopWatch st = new StopWatch();
                        System.out.println("科目开始时间：" + LocalDateTime.now());
                        st.start();
                        String gsUrl = IP + ":" + PORT + "/api/jg/syncbddata/v1.0/bdsyncinterface/syncKmzd";
                        String returnMSG = HttpRequest.post(gsUrl)
                                .header("Content-Type", "application/json")
                                .header("Accept-Language", "zh-CHS")
                                .header("X-ECC-Current-Tenant", ECC)
                                .header("Authorization", Bearer).timeout(200000)
                                .body(GsJson).execute().body();
                        st.stop();
                        System.out.println("科目结束时间：" + LocalDateTime.now());
                        System.out.println("科目接口耗时" + st.getTotalTimeMillis() + "ms");
                        System.out.println(methodName + "科目返回值：" + returnMSG);
                        if (!returnMSG.isEmpty()) {
                            String logInsert = "";
                            JSONObject returnObj = JSONObject.parseObject(returnMSG);
                            if (returnMSG.contains("Code")) {
                                //写入日志表
                                int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常,【" + returnMSG + "】返回值为空！！！", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                                if (loginsert > 0) {
                                    System.out.println("日志写入成功！！");
                                } else {
                                    System.out.println("日志写入失败！！");
                                }

                            } else if (returnObj.get("code").equals("0")) {  //成功
                                int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "成功", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                                if (loginsert > 0) {
                                    //System.out.println("日志写入成功！！");
                                } else {
                                    System.out.println("日志写入失败！！");
                                }
                                //失败
                            } else if (returnObj.get("code").equals("1")) {
                                //写入日志表
                                int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "失败", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                                if (loginsert > 0) {
                                    //System.out.println("日志写入成功！！");
                                } else {
                                    System.out.println("日志写入失败！！");
                                }
                            } else if (returnObj.get("code") == null && ("").equals(returnObj.get("code"))) {
                                //写入日志表
                                int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                                if (loginsert > 0) {
                                    //System.out.println("日志写入成功！！");
                                } else {
                                    System.out.println("日志写入失败！！");
                                }
                            } else {
                                //写入日志表
                                int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                                if (loginsert > 0) {
                                    //System.out.println("日志写入成功！！");
                                } else {
                                    System.out.println("日志写入失败！！");
                                }
                            }
                        }
                        //   }
                    }
                } else {
                    System.out.println(methodName + "暂无新数据推送");
                }
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            //关闭链接
            DataSourceUtil.closeOracleSession();
            DataSourceUtil.closeMysqlSession();
        }
    }
}
